<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>promise2</title>
</head>
<body>
<script src="js/jquery-1.8.1.js"></script>
<script>
/*    $.ajax({
        url:"./data/test.txt",
        success: function (data) {
            console.log(data)
        }
    })*/

{
    //Promise.resolve();
    //返回promise对象
    Promise.resolve(
        $.ajax({
                url: "./data/test.txt"
            })
    ).then(
        success=>{
            console.log(success)
        }
    )
}
{
    let p1 = Promise.resolve(1);
    //等同于下面
    let p2 = new Promise((resolve, reject)=>{
        resolve(1)
    });

    p1.then(
        succ=>{
            console.log("p1",succ)
        },
        err=>{
            console.log("p1-err");
        }
    );
    p2.then(
        succ=>{
            console.log("p2",succ)
        },
        err=>{
            console.log("p2-err");
        }
    )
}{
    let p1 = Promise.reject(1);
    //等同于下面
    let p2 = new Promise((resolve, reject)=>{
        reject(1)
    });

    p1.then(
        succ=>{
            console.log("p1",succ)
        },
        err=>{
            console.log("p1-err");
        }
    );
    p2.then(
        succ=>{
            console.log("p2",succ)
        },
        err=>{
            console.log("p2-err");
        }
    )
}


</script>
</body>
</html>